import { NoSkinCellRenderer } from "../../common/item/NoSkinCellRenderer";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ObjCreate } from "../../common/ObjCreate";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SWrestleToplist } from "../../../../../Message/Public/SWrestleToplist";
import { PlayerUtil } from "../../common/util/PlayerUtil";
import { CareerConfig } from "../../../resource/CareerConfig";
import { ItemData } from "../../../resource/info/ItemData";
import { Cache } from "../../../cache/Cache";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
//class WrestleTopCellRenderer
    
    export  class WrestleTopCellRenderer extends NoSkinCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._textFormatCenter = GlobalStyle.textFormat1;
            this._textFormatCenter.align = flash.text.TextFormatAlign.CENTER;
            this._textFormatGreenCenter = GlobalStyle.textFormatGreen;
            this._textFormatGreenCenter.align = flash.text.TextFormatAlign.CENTER;
            this._tfRank = ObjCreate.createTextField("", 0, 12, 70, 20, this, this._textFormatCenter);
            this._tfName = ObjCreate.createTextField("", 70, 12, 180, 20, this, this._textFormatCenter);
            this._tfName.addEventListener(flash.events.TextEvent.LINK, this.onClickName);
            this._tfCareer = ObjCreate.createTextField("", 250, 12, 70, 20, this, this._textFormatCenter);
            this._tfLevel = ObjCreate.createTextField("", 320, 12, 60, 20, this, this._textFormatCenter);
            this._tfScore = ObjCreate.createTextField("", 380, 12, 80, 20, this, this._textFormatCenter);
            this._tfWarfare = ObjCreate.createTextField("", 460, 12, 80, 20, this, this._textFormatCenter);
            this._tfWinPer = ObjCreate.createTextField("", 540, 12, 70, 20, this, this._textFormatCenter);
            this._tfMoney = ObjCreate.createTextField("", 610, 12, 90, 20, this, this._textFormatCenter);
            this._tfReward = ObjCreate.createTextField("", 700, 12, 100, 20, this, this._textFormatCenter);
            ObjCreate.createBg(0, 40, 800, 2, this, "SplitLine");
            return;
        }

        /* internal  */onClickName(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WrestleGetPlayerInfo, this._topListData.entityId));
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            this._isOnlyMyServer = arg1["onlyMyServer"] as Boolean;
            this._topListData = arg1["list"] as SWrestleToplist;
            this.updateView();
            return;
        }

        /* internal  */updateView(): void
        {
            var loc1=null;
            if (this._topListData) 
            {
                if (this._isOnlyMyServer) 
                {
                    this._tfRank.text = this._topListData.rank.toString();
                }
                else 
                {
                    this._tfRank.text = this._topListData.rankCross.toString();
                }
                this._tfName.htmlText = "<a href=\'event: 1\'><u>" + PlayerUtil.getProxyAndNameByEntityIdAndName(this._topListData.entityId, this._topListData.name) + "</u></a>";
                this._tfCareer.text = CareerConfig.instance.getInfoByCode(this._topListData.career).name;
                this._tfLevel.text = this._topListData.level.toString();
                this._tfScore.text = this._topListData.mark.toString();
                this._tfWarfare.text = this._topListData.warfare.toString();
                this._tfWinPer.text = this._topListData.winPer / 100 + "%";
                this._tfMoney.text = this._topListData.lastMoneyReward.toString();
                if (this._topListData.lastItemReward != 0) 
                {
                    loc1 = new ItemData(this._topListData.lastItemReward);
                    this._tfReward.htmlText = "<u>" + loc1.itemInfo.htmlName + "</u>";
                    this._tfReward.toolTipData = loc1.getToolTipData();
                }
                else 
                {
                    this._tfReward.htmlText = "--";
                }
                if (this._topListData.entityId.id != Cache.instance.role.entityInfo.entityId.id) 
                {
                    this._tfRank.setTextFormat(this._textFormatCenter);
                    this._tfName.setTextFormat(this._textFormatCenter);
                    this._tfCareer.setTextFormat(this._textFormatCenter);
                    this._tfLevel.setTextFormat(this._textFormatCenter);
                    this._tfScore.setTextFormat(this._textFormatCenter);
                    this._tfWarfare.setTextFormat(this._textFormatCenter);
                    this._tfWinPer.setTextFormat(this._textFormatCenter);
                    this._tfMoney.setTextFormat(this._textFormatCenter);
                    if (this._star && this._star.parent) 
                    {
                        this._star.parent.removeChild(this._star);
                    }
                }
                else 
                {
                    this._tfRank.setTextFormat(this._textFormatGreenCenter);
                    this._tfName.setTextFormat(this._textFormatGreenCenter);
                    this._tfCareer.setTextFormat(this._textFormatGreenCenter);
                    this._tfLevel.setTextFormat(this._textFormatGreenCenter);
                    this._tfScore.setTextFormat(this._textFormatGreenCenter);
                    this._tfWarfare.setTextFormat(this._textFormatGreenCenter);
                    this._tfWinPer.setTextFormat(this._textFormatGreenCenter);
                    this._tfMoney.setTextFormat(this._textFormatGreenCenter);
                    if (!this._star) 
                    {
                        this._star = GlobalClass.getBitmap(ImagesConst.ChatGuildMember_star);
                        this._star.x = 0;
                        this._star.y = 10;
                    }
                    this.addChild(this._star);
                }
            }
            return;
        }

        /* internal */ /* var */_tfRank: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfName: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCareer: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfLevel: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfScore: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfWarfare: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfWinPer: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfMoney: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfReward: GTextFiled;

        /* internal */ /* var */_star: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_textFormatCenter: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_textFormatGreenCenter: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_topListData: SWrestleToplist;

        /* internal */ /* var */_isOnlyMyServer: Boolean=false;
    }
